package cesdentalrecord.dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;

  
  
/**
 * This class was autogenerated by Torque on:
 *
 * [Mon Mar 22 12:41:25 CST 2010]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to OralHealthService
 */
public abstract class BaseOralHealthService extends BaseObject
{
    /** The Peer class */
    private static final OralHealthServicePeer peer =
        new OralHealthServicePeer();

        
    /** The value for the oralServiceID field */
    private int oralServiceID;
      
    /** The value for the studentID field */
    private int studentID;
      
    /** The value for the dateOfService field */
    private String dateOfService;
      
    /** The value for the oralProphy field */
    private boolean oralProphy;
      
    /** The value for the tempFilling field */
    private boolean tempFilling;
      
    /** The value for the permFilling field */
    private boolean permFilling;
      
    /** The value for the sealant field */
    private boolean sealant;
      
    /** The value for the exo field */
    private boolean exo;
      
    /** The value for the flouride field */
    private boolean flouride;
      
    /** The value for the consultation field */
    private boolean consultation;
      
    /** The value for the other field */
    private boolean other;
      
    /** The value for the remark field */
    private String remark;
  
    
    /**
     * Get the OralServiceID
     *
     * @return int
     */
    public int getOralServiceID()
    {
        return oralServiceID;
    }

                                              
    /**
     * Set the value of OralServiceID
     *
     * @param v new value
     */
    public void setOralServiceID(int v) throws TorqueException
    {
    
                  if (this.oralServiceID != v)
              {
            this.oralServiceID = v;
            setModified(true);
        }
    
          
                                  
        // update associated Tooth
        if (collTooths != null)
        {
            for (int i = 0; i < collTooths.size(); i++)
            {
                ((Tooth) collTooths.get(i))
                    .setOralServiceID(v);
            }
        }
                      }
  
    /**
     * Get the StudentID
     *
     * @return int
     */
    public int getStudentID()
    {
        return studentID;
    }

                              
    /**
     * Set the value of StudentID
     *
     * @param v new value
     */
    public void setStudentID(int v) throws TorqueException
    {
    
                  if (this.studentID != v)
              {
            this.studentID = v;
            setModified(true);
        }
    
                          
                if (aStudent != null && !(aStudent.getStudentID() == v))
                {
            aStudent = null;
        }
      
              }
  
    /**
     * Get the DateOfService
     *
     * @return String
     */
    public String getDateOfService()
    {
        return dateOfService;
    }

                        
    /**
     * Set the value of DateOfService
     *
     * @param v new value
     */
    public void setDateOfService(String v) 
    {
    
                  if (!ObjectUtils.equals(this.dateOfService, v))
              {
            this.dateOfService = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the OralProphy
     *
     * @return boolean
     */
    public boolean getOralProphy()
    {
        return oralProphy;
    }

                        
    /**
     * Set the value of OralProphy
     *
     * @param v new value
     */
    public void setOralProphy(boolean v) 
    {
    
                  if (this.oralProphy != v)
              {
            this.oralProphy = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the TempFilling
     *
     * @return boolean
     */
    public boolean getTempFilling()
    {
        return tempFilling;
    }

                        
    /**
     * Set the value of TempFilling
     *
     * @param v new value
     */
    public void setTempFilling(boolean v) 
    {
    
                  if (this.tempFilling != v)
              {
            this.tempFilling = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the PermFilling
     *
     * @return boolean
     */
    public boolean getPermFilling()
    {
        return permFilling;
    }

                        
    /**
     * Set the value of PermFilling
     *
     * @param v new value
     */
    public void setPermFilling(boolean v) 
    {
    
                  if (this.permFilling != v)
              {
            this.permFilling = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Sealant
     *
     * @return boolean
     */
    public boolean getSealant()
    {
        return sealant;
    }

                        
    /**
     * Set the value of Sealant
     *
     * @param v new value
     */
    public void setSealant(boolean v) 
    {
    
                  if (this.sealant != v)
              {
            this.sealant = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Exo
     *
     * @return boolean
     */
    public boolean getExo()
    {
        return exo;
    }

                        
    /**
     * Set the value of Exo
     *
     * @param v new value
     */
    public void setExo(boolean v) 
    {
    
                  if (this.exo != v)
              {
            this.exo = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Flouride
     *
     * @return boolean
     */
    public boolean getFlouride()
    {
        return flouride;
    }

                        
    /**
     * Set the value of Flouride
     *
     * @param v new value
     */
    public void setFlouride(boolean v) 
    {
    
                  if (this.flouride != v)
              {
            this.flouride = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Consultation
     *
     * @return boolean
     */
    public boolean getConsultation()
    {
        return consultation;
    }

                        
    /**
     * Set the value of Consultation
     *
     * @param v new value
     */
    public void setConsultation(boolean v) 
    {
    
                  if (this.consultation != v)
              {
            this.consultation = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Other
     *
     * @return boolean
     */
    public boolean getOther()
    {
        return other;
    }

                        
    /**
     * Set the value of Other
     *
     * @param v new value
     */
    public void setOther(boolean v) 
    {
    
                  if (this.other != v)
              {
            this.other = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Remark
     *
     * @return String
     */
    public String getRemark()
    {
        return remark;
    }

                        
    /**
     * Set the value of Remark
     *
     * @param v new value
     */
    public void setRemark(String v) 
    {
    
                  if (!ObjectUtils.equals(this.remark, v))
              {
            this.remark = v;
            setModified(true);
        }
    
          
              }
  
      
    
                  
    
        private Student aStudent;

    /**
     * Declares an association between this object and a Student object
     *
     * @param v Student
     * @throws TorqueException
     */
    public void setStudent(Student v) throws TorqueException
    {
            if (v == null)
        {
                    setStudentID(0);
                  }
        else
        {
            setStudentID(v.getStudentID());
        }
                aStudent = v;
    }

                                            
    /**
     * Get the associated Student object
     *
     * @return the associated Student object
     * @throws TorqueException
     */
    public Student getStudent() throws TorqueException
    {
        if (aStudent == null && (this.studentID > 0))
        {
                          aStudent = StudentPeer.retrieveByPK(SimpleKey.keyFor(this.studentID));
              
            /* The following can be used instead of the line above to
               guarantee the related object contains a reference
               to this object, but this level of coupling
               may be undesirable in many circumstances.
               As it can lead to a db query with many results that may
               never be used.
               Student obj = StudentPeer.retrieveByPK(this.studentID);
               obj.addOralHealthServices(this);
            */
        }
        return aStudent;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
           */
    public void setStudentKey(ObjectKey key) throws TorqueException
    {
      
                        setStudentID(((NumberKey) key).intValue());
                  }
       
                                
            
    /**
     * Collection to store aggregation of collTooths
     */
    protected List collTooths;

    /**
     * Temporary storage of collTooths to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initTooths()
    {
        if (collTooths == null)
        {
            collTooths = new ArrayList();
        }
    }

    /**
     * Method called to associate a Tooth object to this object
     * through the Tooth foreign key attribute
     *
     * @param l Tooth
     * @throws TorqueException
     */
    public void addTooth(Tooth l) throws TorqueException
    {
        getTooths().add(l);
        l.setOralHealthService((OralHealthService) this);
    }

    /**
     * The criteria used to select the current contents of collTooths
     */
    private Criteria lastToothsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getTooths(new Criteria())
     *
     * @throws TorqueException
     */
    public List getTooths() throws TorqueException
    {
        if (collTooths == null)
        {
            collTooths = getTooths(new Criteria(10));
        }
        return collTooths;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this OralHealthService has previously
     * been saved, it will retrieve related Tooths from storage.
     * If this OralHealthService is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getTooths(Criteria criteria) throws TorqueException
    {
        if (collTooths == null)
        {
            if (isNew())
            {
               collTooths = new ArrayList();
            }
            else
            {
                      criteria.add(ToothPeer.ORALSERVICEID, getOralServiceID() );
                      collTooths = ToothPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(ToothPeer.ORALSERVICEID, getOralServiceID());
                      if (!lastToothsCriteria.equals(criteria))
                {
                    collTooths = ToothPeer.doSelect(criteria);
                }
            }
        }
        lastToothsCriteria = criteria;

        return collTooths;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getTooths(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getTooths(Connection con) throws TorqueException
    {
        if (collTooths == null)
        {
            collTooths = getTooths(new Criteria(10), con);
        }
        return collTooths;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this OralHealthService has previously
     * been saved, it will retrieve related Tooths from storage.
     * If this OralHealthService is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getTooths(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collTooths == null)
        {
            if (isNew())
            {
               collTooths = new ArrayList();
            }
            else
            {
                       criteria.add(ToothPeer.ORALSERVICEID, getOralServiceID());
                       collTooths = ToothPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(ToothPeer.ORALSERVICEID, getOralServiceID());
                       if (!lastToothsCriteria.equals(criteria))
                 {
                     collTooths = ToothPeer.doSelect(criteria, con);
                 }
             }
         }
         lastToothsCriteria = criteria;

         return collTooths;
     }

                  
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this OralHealthService is new, it will return
     * an empty collection; or if this OralHealthService has previously
     * been saved, it will retrieve related Tooths from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in OralHealthService.
     */
    protected List getToothsJoinOralHealthService(Criteria criteria)
        throws TorqueException
    {
        if (collTooths == null)
        {
            if (isNew())
            {
               collTooths = new ArrayList();
            }
            else
            {
                            criteria.add(ToothPeer.ORALSERVICEID, getOralServiceID());
                            collTooths = ToothPeer.doSelectJoinOralHealthService(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(ToothPeer.ORALSERVICEID, getOralServiceID());
                        if (!lastToothsCriteria.equals(criteria))
            {
                collTooths = ToothPeer.doSelectJoinOralHealthService(criteria);
            }
        }
        lastToothsCriteria = criteria;

        return collTooths;
    }
                            


          
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("OralServiceID");
              fieldNames.add("StudentID");
              fieldNames.add("DateOfService");
              fieldNames.add("OralProphy");
              fieldNames.add("TempFilling");
              fieldNames.add("PermFilling");
              fieldNames.add("Sealant");
              fieldNames.add("Exo");
              fieldNames.add("Flouride");
              fieldNames.add("Consultation");
              fieldNames.add("Other");
              fieldNames.add("Remark");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("OralServiceID"))
        {
                return new Integer(getOralServiceID());
            }
          if (name.equals("StudentID"))
        {
                return new Integer(getStudentID());
            }
          if (name.equals("DateOfService"))
        {
                return getDateOfService();
            }
          if (name.equals("OralProphy"))
        {
                return new Boolean(getOralProphy());
            }
          if (name.equals("TempFilling"))
        {
                return new Boolean(getTempFilling());
            }
          if (name.equals("PermFilling"))
        {
                return new Boolean(getPermFilling());
            }
          if (name.equals("Sealant"))
        {
                return new Boolean(getSealant());
            }
          if (name.equals("Exo"))
        {
                return new Boolean(getExo());
            }
          if (name.equals("Flouride"))
        {
                return new Boolean(getFlouride());
            }
          if (name.equals("Consultation"))
        {
                return new Boolean(getConsultation());
            }
          if (name.equals("Other"))
        {
                return new Boolean(getOther());
            }
          if (name.equals("Remark"))
        {
                return getRemark();
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(OralHealthServicePeer.ORALSERVICEID))
        {
                return new Integer(getOralServiceID());
            }
          if (name.equals(OralHealthServicePeer.STUDENTID))
        {
                return new Integer(getStudentID());
            }
          if (name.equals(OralHealthServicePeer.DATEOFSERVICE))
        {
                return getDateOfService();
            }
          if (name.equals(OralHealthServicePeer.ORALPROPHY))
        {
                return new Boolean(getOralProphy());
            }
          if (name.equals(OralHealthServicePeer.TEMPFILLING))
        {
                return new Boolean(getTempFilling());
            }
          if (name.equals(OralHealthServicePeer.PERMFILLING))
        {
                return new Boolean(getPermFilling());
            }
          if (name.equals(OralHealthServicePeer.SEALANT))
        {
                return new Boolean(getSealant());
            }
          if (name.equals(OralHealthServicePeer.EXO))
        {
                return new Boolean(getExo());
            }
          if (name.equals(OralHealthServicePeer.FLOURIDE))
        {
                return new Boolean(getFlouride());
            }
          if (name.equals(OralHealthServicePeer.CONSULTATION))
        {
                return new Boolean(getConsultation());
            }
          if (name.equals(OralHealthServicePeer.OTHER))
        {
                return new Boolean(getOther());
            }
          if (name.equals(OralHealthServicePeer.REMARK))
        {
                return getRemark();
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getOralServiceID());
            }
              if (pos == 1)
        {
                return new Integer(getStudentID());
            }
              if (pos == 2)
        {
                return getDateOfService();
            }
              if (pos == 3)
        {
                return new Boolean(getOralProphy());
            }
              if (pos == 4)
        {
                return new Boolean(getTempFilling());
            }
              if (pos == 5)
        {
                return new Boolean(getPermFilling());
            }
              if (pos == 6)
        {
                return new Boolean(getSealant());
            }
              if (pos == 7)
        {
                return new Boolean(getExo());
            }
              if (pos == 8)
        {
                return new Boolean(getFlouride());
            }
              if (pos == 9)
        {
                return new Boolean(getConsultation());
            }
              if (pos == 10)
        {
                return new Boolean(getOther());
            }
              if (pos == 11)
        {
                return getRemark();
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(OralHealthServicePeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    OralHealthServicePeer.doInsert((OralHealthService) this, con);
                    setNew(false);
                }
                else
                {
                    OralHealthServicePeer.doUpdate((OralHealthService) this, con);
                }
            }

                                      
                
            if (collTooths != null)
            {
                for (int i = 0; i < collTooths.size(); i++)
                {
                    ((Tooth) collTooths.get(i)).save(con);
                }
            }
                          alreadyInSave = false;
        }
      }


                          
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  oralServiceID ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
            setOralServiceID(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
            setOralServiceID(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getOralServiceID());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public OralHealthService copy() throws TorqueException
    {
        return copyInto(new OralHealthService());
    }
  
    protected OralHealthService copyInto(OralHealthService copyObj) throws TorqueException
    {
          copyObj.setOralServiceID(oralServiceID);
          copyObj.setStudentID(studentID);
          copyObj.setDateOfService(dateOfService);
          copyObj.setOralProphy(oralProphy);
          copyObj.setTempFilling(tempFilling);
          copyObj.setPermFilling(permFilling);
          copyObj.setSealant(sealant);
          copyObj.setExo(exo);
          copyObj.setFlouride(flouride);
          copyObj.setConsultation(consultation);
          copyObj.setOther(other);
          copyObj.setRemark(remark);
  
                    copyObj.setOralServiceID(0);
                                                                              
                                      
                
        List v = getTooths();
        for (int i = 0; i < v.size(); i++)
        {
            Tooth obj = (Tooth) v.get(i);
            copyObj.addTooth(obj.copy());
        }
                    
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public OralHealthServicePeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("OralHealthService:\n");
        str.append("OralServiceID = ")
           .append(getOralServiceID())
           .append("\n");
        str.append("StudentID = ")
           .append(getStudentID())
           .append("\n");
        str.append("DateOfService = ")
           .append(getDateOfService())
           .append("\n");
        str.append("OralProphy = ")
           .append(getOralProphy())
           .append("\n");
        str.append("TempFilling = ")
           .append(getTempFilling())
           .append("\n");
        str.append("PermFilling = ")
           .append(getPermFilling())
           .append("\n");
        str.append("Sealant = ")
           .append(getSealant())
           .append("\n");
        str.append("Exo = ")
           .append(getExo())
           .append("\n");
        str.append("Flouride = ")
           .append(getFlouride())
           .append("\n");
        str.append("Consultation = ")
           .append(getConsultation())
           .append("\n");
        str.append("Other = ")
           .append(getOther())
           .append("\n");
        str.append("Remark = ")
           .append(getRemark())
           .append("\n");
        return(str.toString());
    }
}
